#ifndef Mutex_H
#define Mutex_H
#include <Windows.h>
#include <stdio.h>

// Mutex wrapper class, Windows implementation
class Thread_Mutex
{

public:
    Thread_Mutex()
	{
		hMutex = CreateMutex(NULL, FALSE, NULL);
	}

    ~Thread_Mutex() {};

	void wait(void)
	{
		DWORD result = WaitForSingleObject(hMutex, INFINITE);
		if (result != WAIT_OBJECT_0) {
			printf("Mutex error 0x%x08\n", result);
		}
	}
	
	void wait(int timeout)
	{
		WaitForSingleObject(hMutex, timeout);
	}

	void signal(void)
	{
		ReleaseMutex(hMutex);
	}

private:
    HANDLE hMutex;
};

#endif